草庐IT

MySQL INSERT INTO 语法

全部标签

C++:制作对象的浅表拷贝a)语法b)我需要删除它吗

我有一个类MyClassA。在其构造函数中,我将指针传递给B类的实例。我有一些与此相关的非常基本的问题。(1)首先,下面的代码是否正确?(浅拷贝的代码和methodA()中的代码)MyClassA::MyClassA(B*b){this.b=b;}voidMyClassA::methodA(){inti;i=b.getFooValue();//ShouldIratherbeusingthearrowoperatorhere??//i=b->getFooValue()}(2)我猜我不需要担心在析构函数~MyClassA()中删除MyClassA.b的内存,因为它没有分配。我对吗?谢谢更新

c++ - 使用预处理器更改语言语法

很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visitthehelpcenter.关闭11年前。我读到Objective-C是通过使用预处理器指令将Smalltalk的特性添加到C而制成的,这让我有点好奇所以我开始在C++中修补预处理器,只是因为我很无聊并想出了这个:#include#include#defineConstantconst#defineIntegerint#defineRealdouble#defineBooleanbool#defineCharacterchar#defi

c++ - Boost::Spirit 中的复合语法

我有以下语法,它按预期工作。structquery_term{std::stringterm;boolis_tag;query_term(conststd::string&a,booltag=false):term(a),is_tag(tag){}};templatestructquery_grammar:grammar(),space_type>{query_grammar():query_grammar::base_type(query){word%=+alnum;tag=(omit[word>>':']>>word[_val=phoenix::construct(_1,true)

c++ - 原始类型初始化的构造函数语法和赋值语法之间的差异

这个问题在这里已经有了答案:Isthereadifferencebetweencopyinitializationanddirectinitialization?(9个回答)关闭9年前。阅读同事编写的一些代码时,我无意中发现了使用构造函数语法来初始化基本类型变量的方法。即如下所示:#includeintmain(){usingnamespacestd;//initializedusingassignementsyntax(copyinitialisation)inttiti=20;cout我的自然倾向是坚持使用赋值语法,因为它是历史悠久的语法,很容易理解,并且存在明显的兼容性问题(构造

c++ - 将 boost filtering_stream 替换为 std::ofstream 的参数语法

关于boostfiltering_streams的一些基本问题。我有几十个函数接受std::ofstream&的参数voidfoo(std::ofstream&outStream){//lotsofoperations,likethis:outStream现在我想使用boostfiltering_stream输出到一个压缩的ZIP文件。经常引用的用于打包和解包的boostfiltering_streams测试代码经过编译、链接和完美运行。我想替换filtering_stream:voidStreamSomeCompressedTextToFile(char*fileName){ofst

c++ - 递归案例结束时的模板语法错误

有人能告诉我下面递归特化结束的语法有什么问题吗?我以为我遵守了所有规则。#includetemplateclassStringList{templateclassAddStrings;public:templatevoidaddStrings(Args&&...args){AddStrings()(args...);}};templatetemplateclassStringList::AddStrings:AddStrings{public:voidoperator()(First&&first,Rest&&...rest){//dowhateverAddStrings::opera

C++ 这个很少使用的构造函数语法是什么?

编辑:我认为这不是thisotherquestion的拷贝,因为另一个问题只是在构造函数中将()转换为{}。而我注意到当构造函数在struct中定义时的不同行为,而不是在class中。(而且,正如评论中所指出的,这是关于使用构造函数而不是编写它们。)但我以前错了。我在辅导时遇到了构造函数的这种奇怪的(对我来说)语法:Fooobj{i,j};起初我认为它行不通,并告诉学生重写它——但他们坚持认为它行得通,并告诉我他们从cplusplus.com上提取了示例,towhichI'venotbeenabletofindareference,所以我还是尝试了一下......它奏效了。所以我试验了

c++ - 有什么语法可以缩短这段代码吗?

无论如何我可以缩短这段代码吗?太笨重了!switch(line){case1:llemu::editLable(line1,fmt);break;case2:llemu::editLable(line2,fmt);break;case3:llemu::editLable(line3,fmt);break;case4:llemu::editLable(line4,fmt);break;case5:llemu::editLable(line5,fmt);break;case6:llemu::editLable(line6,fmt);break;case7:llemu::editLable(

c++ - 具有显式模板实例化的未解析外部。什么是声明语法?

这里有一些简化的代码来演示我遇到的问题。我有一个模板函数,我只想为其编译某些固定的实例。函数声明是://***template.h***intsquare(intx);doublesquare(doublex);定义是://***template.cpp***#include"template.h"//(templatedefinitionunusuallyinacoderatherthanheaderfile)templateTsquare(Tx){returnx*x;}//explicitinstantiationstemplateintsquare(intx);templatef

c++ - 一个c++语法问题(一种结构方法)

在下面的代码中,:next(next_par),info(info_par)是什么意思?structlist_node:publicmemory::SqlAlloc{list_node*next;void*info;list_node(void*info_par,list_node*next_par):next(next_par),info(info_par)/*what'sthemeaningof:next(next_par),info(info_par)?*/{}list_node(){info=0;next=this;}};看起来是想为info(info_par)赋值info_p